<template>
  <div>
    <goga-header title="设置">
      <div slot="left">
        <span @click="goBack">
          <icon symbol="back"> </icon>
        </span>
      </div>
    </goga-header>
    <div v-if="account.data">
      <div >
        <div class="setting-tit">售后服务</div>
        <cell title="联系客服" href="tel:4001681520"  is-link>
          <span style="color:#ffb230 ">400-1681-520</span>
        </cell>
        <div class="setting-tit">个人设置</div>
        <div @click="link({name:'setInfo'})">
          <cell title="个人资料"   is-link>
            <icon symbol="right"></icon>
          </cell>
        </div>

        <cell title="绑定手机" v-if="!account.data.uPhoneConfirm" is-link>
          <icon symbol="right"></icon>
        </cell>
        <div class="setting-tit">关于果加</div>
        <div @click="link({name:'about'})">
          <cell title="关于我们"   is-link>
            <icon symbol="right"></icon>
          </cell>
        </div>
        <div @click="link({name:'join'})">
          <cell title="加入我们" is-link>
            <icon symbol="right"></icon>
          </cell>
        </div>
        <div @click="kefu">
          <cell title="上门退换货" is-link>
          </cell>
        </div>
        <div @click="kefu">
          <cell title="同城免费送达"   is-link>
          </cell>
        </div>
        <div @click="kefu">
          <cell title="优质水果保证"  is-link>
          </cell>
        </div>

      </div>
      <button type="button" class="btn-logout" @click="loginout">
        账户注销
      </button>
    </div>

  </div>
</template>

<script lang="babel">
  import api from '@api'
  import {mapGetters} from 'vuex'
  import {cookie} from '@utils'
  import gogaHeader from '@components/goga-header'
  import Icon from '@components/icon'
  import Cell from '@components/cell'
  const fetchAccountData = async (store) => {
    return await store.dispatch('global/user/getUser')
  }
  export default {
    components: {
      gogaHeader,
      Icon,
      Cell
    },
    computed: {
      ...mapGetters({
        account: 'global/user/getAccount'
      })
    },
    async mounted () {
      if(!this.account.data) {
        fetchAccountData(this.$store)
      }
    },
    methods: {
      goBack() {
        this.$router.go(-1);
      },
      kefu() {
      },
      link (route) {
        if (this.isLogin) {
          this.$router.push(route)
        } else {
          this.$router.push({name: 'login', query:{redirect: '/setting'}})
        }
      },
      async loginout() {
        let self = this
        let {data:{StatusCode}} = await api.get('api/v1/LogReg/logOut.ashx')
        if (StatusCode === '200') {
          cookie('TOKEN', '')
          this.$store.dispatch('global/toast', '注销成功');
          this.$router.push({name: 'index'})
        }
      },
      kefu () {
        window.location.href= 'tel:4001681520'
      }
    }
  }
</script>

<style lang="less">
  @import "index.less";
</style>
